/**
 * @description 加载外部js
 */
export function asyncLoadJs(url) {
    return new Promise((resolve, reject) => {
        const srcArr = document.getElementsByTagName("script")
        let hasLoaded = false
        for (let i = 0; i < srcArr.length; i++) {
            hasLoaded = (srcArr[i].src === url) ? true : false
        }
        if (hasLoaded) {
            resolve()
        } else {
            const script = document.createElement('script')
            script.type = 'text/javascript'
            script.src = url
            document.head.appendChild(script)
            script.onload = () => resolve()
            script.onerror = () => reject()
        }
    })
}

/**
 * @description 加载外部css
 */
export function loadCss(url) {
    const css = document.createElement('link')
    css.href = url
    css.rel = 'stylesheet'
    css.type = 'text/css'
    document.head.appendChild(css)
}